package com.autumn.platform.auth.core.access.impl;

import com.autumn.platform.auth.core.access.IPermission;
import com.autumn.platform.core.context.response.impl.ResponseContext;

public class AccessControllerContext extends ResponseContext {

    /**
     * 
     */
    private static final long serialVersionUID = 260416319499872430L;

    private IPermission permission;

    private boolean locked = false;

    public AccessControllerContext() {
        super();
    }

    public AccessControllerContext(String code, String message) {
        super(code, message);
    }

    public IPermission getPermission() {
        return permission;
    }

    public void setPermission(IPermission permission) {
        validate();
        this.permission = permission;
    }

    @Override
    public void setCode(String code) {
        validate();
        super.setCode(code);
    }

    /* package */void setLocked(boolean locked) {
        this.locked = locked;
    }

    protected void validate() {
        if (locked) {
            throw new IllegalStateException("The AccessControllerContext state is locked. If you need to modify the state, modify it in the IAccessControllerHandler implementation class");
        }
    }
}
